package com.bj.zspace.cat.controller;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Transaction;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author:liuwenqing
 * @Date:2024/12/13 18:05
 * @Description:
 **/
@RestController
public class StorageTest {

    @GetMapping(value = "/storage/cache")
    public String cache() {
        Transaction t = Cat.newTransaction("Cache.User", "get");
        try {
            TimeUnit.SECONDS.sleep(1);
            Cat.logEvent("User.server", "127.0.0.1");
        } catch (Exception e) {
            t.setStatus(e);
        } finally {
            t.complete();
        }
        return "ok";
    }

    @GetMapping(value = "/storage/sql")
    public String sql() {
        Transaction t = Cat.newTransaction("SQL", "select");
        try {
            TimeUnit.SECONDS.sleep(1);
            Cat.logEvent("SQL.Method", "update");
            Cat.logEvent("SQL.Database", "jdbc:mysql://10.2.57.60:3306/cat_db");
        } catch (Exception e) {
            t.setStatus(e);
        } finally {
            t.complete();
        }
        return "ok";
    }

    @GetMapping(value = "/storage/rpc")
    public String rpc() {
        Transaction t = Cat.newTransaction("PigeonCall", "call");
        try {
            TimeUnit.SECONDS.sleep(1);
            Cat.logEvent("PigeonCall.app", "user-service");
            Cat.logEvent("PigeonCall.server", "127.0.0.1");
        } catch (Exception e) {
            t.setStatus(e);
        } finally {
            t.complete();
        }
        return "ok";
    }

}
